$(function () {
    layui.use(['table'],function () {
        var table = layui.table;
        table.render({
            elem:'#listSplit',
            url:'/pages/back/line/listSplit',
            page:true,
            limit:10,
            toolbar: '#toolbarDemo',//开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            cols:[[
                {field:'lid',title:'线路编号',sort: true, fixed: 'left'},
                {field:'start',title:'始发地'},
                {field:'end',title:'目的地'},
                {field:'status',title:'线路状态',templet:'#status'},
                {field:'right',title:'操作',align:'center',toolbar:'#barOption'},

            ]],
            id: 'testReload'
        });
        var $ = layui.$, active = {
            reload: function(){
                var name = $('#demoReload').serialize();

                //执行重载
                table.reload('testReload', {

                    url:'/pages/back/line/findByName?'+name,
                    where: {
                        key: {
                            name: name
                        }
                    },
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.on('tool(listSplit)',function (obj) {
            var data = obj.data;
            if(obj.event == "edit"){
                var lid = data.lid;
                $.ajax({
                    url:'/pages/back/line/edit',
                    type:'post',
                    data:{"lid":lid},
                    success:function (data) {
                        if(data=="success"){
                            layer.msg("修改成功",{time:1000,icon:1,end:function () {
                                    window.location.href="/pages/back/line/listSplitPre"
                                }})
                        }else if (data=="isEmpty"){
                            layer.msg("数据有误",{time:1000,icon:2})
                        }else{
                            layer.msg("修改失败",{time:1000,icon:2})
                        }
                    }
                })
            }
        })
    })
})